package com.njxxted.activiti.modules.business.leave.controller;

import com.google.common.collect.Maps;
import com.njxxted.activiti.common.response.ResponseVo;
import com.njxxted.activiti.common.util.PageUtil;
import com.njxxted.activiti.common.util.StringUtils;
import com.njxxted.activiti.modules.base.controller.BaseController;
import com.njxxted.activiti.modules.business.leave.entity.BusLeaveReqEntity;
import com.njxxted.activiti.modules.business.leave.service.BusLeaveService;
import com.njxxted.activiti.modules.process.defintion.service.IActDefinitionService;
import com.njxxted.activiti.modules.process.extend.entity.ExtendActInstanceEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;


/**
 * 描述：请假流程业务表 exception
 * <p>
 * 作者：HuTongFu
 * 邮箱：hu_tongfu@163.com
 * 时间：2019-08-07 14:18:16
 */
@Api(tags = "请假流程业务表")
@RestController
@RequestMapping("bus/leave")
public class BusLeaveController extends BaseController {

    @Resource
    private BusLeaveService busLeaveService;

    @Resource
    private IActDefinitionService iActDefinitionService;

    @ApiOperation(value = "查询", notes = "分页查询")
    @GetMapping("/list")
    public ResponseVo list(BusLeaveReqEntity param) {
        PageUtil<BusLeaveReqEntity> busLeaveList = busLeaveService.queryList(param);
        return ResponseVo.ok(busLeaveList);
    }

    @ApiOperation(value = "查询", notes = "根据主键id查询")
    @GetMapping("/info/{id}")
    public ResponseVo info(@PathVariable("id") String id) {
        BusLeaveReqEntity busLeaveEntity = busLeaveService.queryObject(id);
        return ResponseVo.ok(busLeaveEntity);
    }

    @ApiOperation(value = "保存或者修改")
    @PostMapping("/save")
    @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
    public ResponseVo save(BusLeaveReqEntity param, HttpServletRequest request) {
        String id = busLeaveService.save(param);
        Map<Object, Object> map = Maps.newHashMap();
        map.put("businessId", id);
        return ResponseVo.ok(map);
    }

    @ApiOperation(value = "修改", notes = "修改")
    @PutMapping("/update")
    public ResponseVo update(BusLeaveReqEntity busLeaveEntity) {
        int i = busLeaveService.update(busLeaveEntity);
        if (i > 0)
            return ResponseVo.ok();
        else
            return ResponseVo.error();
    }

    @ApiOperation(value = "删除", notes = "删除")
    @PostMapping("/delete")
    public ResponseVo delete(String[] ids) {
        int i = busLeaveService.deleteBatch(ids);
        if (i > 0)
            return ResponseVo.ok();
        else
            return ResponseVo.error();
    }

}
